#lang racket

(define (make-account balance password)
  (define (withdraw amount)
    (if (>= balance amount)
        (begin (set! balance (- balance amount))
               balance)
        "not enough credits on account"))
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)
  (define (dispatch pw m)
    (if (eq? password pw)
        (cond ((eq? m 'withdraw) withdraw)
              ((eq? m 'deposit) deposit)
              ((eq? m 'test) 'ok)
              (else (error "unknown parameter: " 
                           m)))
        (begin (display "wrong password")
               false)))
  dispatch)

(define (make-joint account old-pw new-pw)
  (define (dispatch pw m)
    (if (eq? pw new-pw)
        (account old-pw m)
        (account false m)))
  (if (account old-pw 'test)
      dispatch
      false))

(define acc (make-account 100 '1024))

((acc '1024 'withdraw) 40)

(define acc2 (make-joint acc '1024 '102400))

((acc2 '102400 'withdraw) 30)

((acc2 '102400 'deposit) 20)

((acc '1024 'withdraw) 10)

